package com.fintecher.controller;

import com.fintecher.pojo.Buyers;
import com.fintecher.service.IBuyersService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/buyers")
public class BuyersController {
    @Resource
    private IBuyersService buyersService;

    //首页  点击login.jsp “提交” 到首页并 获取首页买方市场的产品列表
    @RequestMapping(value = "getBuyersList")
    public String getBuyersList(HttpServletRequest request, Model model) {
        List<Buyers> lists = this.buyersService.getBuyersList();
        model.addAttribute("lists", lists);
        //控制main.jsp中的属性
        model.addAttribute("main_sell_class", "");
        model.addAttribute("main_buy_class", "active");

        return "/main";
    }

    //票据行情  获取买方市场的产品列表
    @RequestMapping(value = "getBuyersList2")
    public String getBuyersList2(HttpServletRequest request, Model model) {

        //用来控制bill_market样式
        model.addAttribute("sell_active_class", "");
        model.addAttribute("buy_active_class", "active user-mes");
        model.addAttribute("iframe_src", request.getContextPath() + "/buyers/buy_market");

        model.addAttribute("companyName", request.getSession().getAttribute("companyName"));
        return "bill_market";
    }

    //票据行情  点击买方市场 跳转到buy_market.jsp
    @RequestMapping(value = "buy_market")
    public String buy_market(HttpServletRequest request, Model model) {

        List<Buyers> lists = this.buyersService.getBuyersList();
        model.addAttribute("lists", lists);
        return "buy_market";
    }

    //接受buy_market.jsp中ajax传来的数据
    @RequestMapping(value = "getAjax")
    public Buyers getAjax(HttpServletRequest request, Model model,
                          int positiveType,
                          double positiveMoney_min,
                          double positiveMoney_max,
                          String inquiry,
                          int acceptorType,
                          int positiveTime,
                          String positiveAddress) {

        System.out.println("=========================================");
        System.out.println(positiveType + "," + positiveMoney_min + "," + positiveMoney_max + "," + inquiry +
                "," + acceptorType + "," + positiveTime + "," + positiveAddress);
        System.out.println("=========================================");

        Buyers buyers = new Buyers();

        buyers.setPositiveType(positiveType);
        buyers.setPositiveMoney_min(positiveMoney_min);
        buyers.setPositiveMoney_max(positiveMoney_max);
        buyers.setInquiry(inquiry);
        buyers.setAcceptorType(acceptorType);
        buyers.setPositiveAddress(positiveAddress);

        return buyers;
    }


}



